﻿package view.mainUI
{
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.consts.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import uiresource.*;

    public class LeftKaiQi extends KqUI
    {
        private var _data:Object = null;
        private var _cfgLeftGuide:Object = null;
        private var _tween:TweenMax;
        private var _bitmap:Bitmap;
        private var _cont:Sprite;
        private var lvmc:XMLMovieClip;
        private var img:Image;
        private var mColorFilter:ColorMatrixFilter;

        public function LeftKaiQi(param1:int)
        {
            this.mColorFilter = new ColorMatrixFilter([1, 0, 0, 0, 45, 0, 1, 0, 0, 45, 0, 0, 1, 0, 45, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]);
            this.img = new Image();
            this.img.x = 21;
            this.img.y = 13;
            this._cont = new Sprite();
            this.addChildAt(this._cont, 0);
            this.y = param1;
            this._cont.x = 47;
            this._cont.y = 47;
            this.initEvent();
            this.addChild(this.img);
            UIVisibleManager.instance.register("kaiqi", this, UIVisibleManager.VLeft);
            return;
        }// end function

        private function initEvent() : void
        {
            this.addEventListener(MouseEvent.ROLL_OVER, this.onOverHandler);
            this.addEventListener(MouseEvent.ROLL_OUT, this.onOutHandler);
            this.addEventListener(MouseEvent.MOUSE_UP, this.showKq);
            return;
        }// end function

        protected function showKq(event:MouseEvent) : void
        {
            var _loc_2:* = int(GlobalLayer.instance.root.stageWidth / 2 - 310);
            var _loc_3:* = int(GlobalLayer.instance.root.stageHeight / 2 - 250);
            if (this._data)
            {
                PluginManager.instance.changePlugin("leftkq", new Point(mouseX, mouseY), this._data, new Point(_loc_2, _loc_3));
            }
            return;
        }// end function

        protected function onOutHandler(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            this.filters = [];
            return;
        }// end function

        protected function onOverHandler(event:MouseEvent) : void
        {
            if (this._data)
            {
                ModelProxy.change("tips", "normal", {data:this._data.tips, p:new Point(GlobalLayer.instance.root.mouseX, GlobalLayer.instance.root.mouseY)});
            }
            this.filters = [this.mColorFilter];
            return;
        }// end function

        public function show(param1:int) : void
        {
            var _loc_2:Object = null;
            var _loc_3:String = null;
            this._data = null;
            if (param1 > 80 && param1 == 0)
            {
                if (this.lvmc && this.lvmc.parent)
                {
                    this.lvmc.parent.removeChild(this.lvmc);
                    this.lvmc.dispose();
                    this.lvmc = null;
                }
                this.visible = false;
                UIVisibleManager.instance.cancel("kaiqi");
                return;
            }
            if (this._cfgLeftGuide == null)
            {
                this._cfgLeftGuide = ConfigDictionary.data.leftguide;
            }
            if (this._cfgLeftGuide.length > 0)
            {
                for each (_loc_2 in this._cfgLeftGuide)
                {
                    
                    if (_loc_2.level - param1 <= 5 && _loc_2.level > param1)
                    {
                        this._data = _loc_2;
                        break;
                    }
                }
            }
            if (this._data)
            {
                if (this._data.id == 7)
                {
                    lvnum.visible = false;
                    lv_img.url = "cs2_kaiqi/guide_boss.png";
                }
                else
                {
                    lvnum.visible = true;
                    lvnum.url = "png.common.add_" + (this._data.level - param1);
                    lv_img.url = "cs2_kaiqi/cs2_no.png";
                }
                label_name.text = this._data.name;
                this._data.relv = this._data.level - param1;
                _loc_3 = "assets/images/lvguide/" + this._data.icon + Config.IconExtension;
                App.mloader3.loadBMD(Config.getUrl(_loc_3, ResourceType.NORMAL), 1, new Handler(this.onComp));
                UIVisibleManager.instance.register("kaiqi", this, UIVisibleManager.VLeft);
                this.visible = true;
            }
            else
            {
                UIVisibleManager.instance.cancel("kaiqi");
                this.visible = false;
            }
            return;
        }// end function

        private function Loaded(param1) : void
        {
            this.lvmc = new XMLMovieClip("png.leftview.lvguide", new XML(new MainEmbeds.lvguideXML()));
            this.lvmc.x = -17;
            this.lvmc.y = -22;
            this.lvmc.interval = 1000 / 8;
            this.lvmc.blendMode = BlendMode.ADD;
            this.lvmc.mouseChildren = false;
            this.lvmc.mouseEnabled = false;
            this.addChild(this.lvmc);
            return;
        }// end function

        private function onComp(param1:BitmapData) : void
        {
            var _loc_2:BitmapData = null;
            if (this.img.bitmapData != param1)
            {
                this.img.bitmapData = param1;
                if (this._bitmap)
                {
                    if (this._bitmap.parent)
                    {
                        this._bitmap.parent.removeChild(this._bitmap);
                    }
                    if (this._bitmap.bitmapData)
                    {
                        this._bitmap.bitmapData.dispose();
                        this._bitmap.bitmapData = null;
                    }
                }
                else
                {
                    this._bitmap = new Bitmap();
                }
                _loc_2 = new BitmapData(this.width, this.height, true, 0);
                _loc_2.draw(this);
                this._bitmap.bitmapData = _loc_2;
                this._cont.addChild(this._bitmap);
                this._bitmap.x = -47;
                this._bitmap.y = -47;
            }
            if (this._tween)
            {
                this._tween.kill();
            }
            this._cont.scaleX = 1;
            this._cont.scaleY = 1;
            this._cont.alpha = 0.6;
            this._tween = TweenMax.to(this._cont, 0.8, {scaleX:1.5, scaleY:1.8, repeat:2, alpha:0, onComplete:this.completeFunc, repeatDelay:1});
            return;
        }// end function

        private function completeFunc() : void
        {
            this._tween = null;
            this._cont.scaleX = 1;
            this._cont.scaleY = 1;
            this._cont.alpha = 0.6;
            return;
        }// end function

    }
}
